package cn.iocoder.yudao.module.shop.statistics.service;

import cn.iocoder.yudao.framework.business.basic.pojo.vo.UserSimpleVO;
import cn.iocoder.yudao.framework.qrcode.pojo.QrCodePaymentType;
import cn.iocoder.yudao.framework.qrcode.util.QrCodeUtils;
import cn.iocoder.yudao.module.api.brokerage.user.BrokerageUserApi;
import cn.iocoder.yudao.module.api.member.assets.MemberDigitalAssetsApi;
import cn.iocoder.yudao.module.api.member.user.MemberUserApi;
import cn.iocoder.yudao.module.api.shop.info.ShopInfoApi;
import cn.iocoder.yudao.module.api.shop.revenue.ShopRevenueApi;
import cn.iocoder.yudao.module.api.trade.order.TradeOrderApi;
import cn.iocoder.yudao.module.shop.statistics.vo.MerchantCenterSummaryVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/05/06
 */
@Service
public class MerchantCenterSummaryService {
    @Resource
    private ShopInfoApi shopInfoApi;
    @Resource
    private ShopRevenueApi shopRevenueApi;
    @Resource
    private TradeOrderApi tradeOrderApi;
    @Resource
    private MemberUserApi memberUserApi;
    @Resource
    private MemberDigitalAssetsApi memberDigitalAssetsApi;
    @Resource
    private BrokerageUserApi brokerageUserApi;

    public MerchantCenterSummaryVO getMySummary(Long userId, Long shopId) {
        MerchantCenterSummaryVO summaryVO = new MerchantCenterSummaryVO();
        summaryVO.setShop(shopInfoApi.getShopInfo(shopId));
        QrCodePaymentType qrCodePaymentType = new QrCodePaymentType();
        qrCodePaymentType.setShopId(shopId);
        UserSimpleVO user = memberUserApi.getUser(userId);
        qrCodePaymentType.setMemberNo(user == null ? "" : user.getNo());
        summaryVO.setQrcode(QrCodeUtils.generatePngAsUri(qrCodePaymentType));
        summaryVO.setOrderCount(tradeOrderApi.getOrderSummaryByShopId(shopId));
        summaryVO.setRevenueCount(shopRevenueApi.getRevenueCount(shopId));
        //summaryVO.setVipCount(vipUserApi.getVipSummaryByShopId(shopId));
        summaryVO.setVipCount(brokerageUserApi.getVipSummary(userId));
        summaryVO.setDigitalAssets(memberDigitalAssetsApi.getDetail(userId));
        return summaryVO;
    }

}
